Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
NOTE: This is still very much an active repo. We just haven't needed to change anything in a while. Any feature requests, issues or inquiries will be answered promptly.
nodulejs is a lightweight utility based on node/express, whose sole purpose is to discover and initialize web components (standard AMD Javascript objects) called "nodules". Nodules are tied to one or more express routes, and attached to each incoming express request as req.nodule.
A nodule looks like this:
module.exports = function(app) {
return {
route: '/home',
middlewares: [getProfile, getMoreData],
};
var getProfile = function(req, res, next) {
// make call to an API or database
};
var getMoreData = function(req, res, next) {
// make another async DB/API call which is dependent on getProfile
// do business logic on returned data
// render template
};
};
Which has the exact same behavior as this:
// filename app/myModule.js
module.exports = function(app) {
app.get('/home', getProfile, getMoreData);
var getProfile = function(req, res, next) {
// make call to an API or database
};
var getMoreData = function(req, res, next) {
// make another async DB/API call which is dependent on getProfile
// do business logic on returned data
// render template
};
};
// in app.js or some sub component:
require('./app/myModule.js');
But notice that in the nodulejs example, it is not necessary to require the component myModule.js from another file. The nodule is discovered automatically by the nodulesjs framework - based on configurable file search patterns. This makes it less onerous to reorganize code. Renaming files, moving files, creating subdirectories are all much easier because there is no path to maintain off in another file.
Conversely a nodule's route is not tied to its filename or path. We feel this is the best of both worlds - as files can be renamed and moved w/o impacting the back end or front end code. Developers are more likely to rename and reorganize files - which results in tigher, more self-explanatory code. Each nodule is roughly 1-1 with a web route (although it can serve multiple routes). Our experience is that in large distributed teams, this separation of features into bite-sized files aids development considerably.
$ npm install nodulejs
require('nodulejs')(app, config);
app = express instance
config = any custom properties you want to add or defaults you want to override, see the demoApp
There are 3 global config properties:
There are 4 local properties unique to each nodule:
A nodule can have any properties you want to add*, which will be propagated throughout the middleware chain as as req.nodule. But nodulejs only cares about 4 core properties, which are needed to register express middleware at app-init time:
*nodulejs can be a building block for more complex behaviors. See the yukon component framework for an example.
Download nodulejs - https://github.com/jackspaniel/nodulejs/archive/master.zip
$ npm install
$ make test
node app
(homePage.js from the demoApp)
module.exports = function(app) {
return {
route: ['/', '/home', '/special'],
doNoduleBusinessLogic: function(req, res) {
this.templateName = (req.path.indexOf('special') > -1)
? 'altHomePage.jade'
: 'homePage.jade';
}
};
};
(submitForm.js from the demoApp)
module.exports = function(app) {
return {
route : '/json/submitForm',
routeVerb: 'post',
doPreFormBusinessLogic: function(req, res) {
this.dbParams = {param1: req.body ? req.body.param1 : null}; // in real life don't forget to sanitize query params!
},
doPostFormBusinessLogic: function(req, res) {
if (req.nodule.responseData.dbMsg.indexOf('valid data') === -1)
this.customMsg = 'Form submit failed, please supply valid param1';
}
};
};
(404 error nodule - shows routeIndex and one-off middleware)
module.exports = function(app) {
return {
route: '*',
routeIndex: 1000, // high routes are registered last
middlewares: [
function(req, res, next) {
req.nodule.debug('404 error middleware called!');
res.send('<html><body><h1>404 error!</h1></body></html>');
}
]
};
};
(from demoApp.js - shows defining several nodule-dependent middleware chains at app init time, and adding extra nodule properties)
var config = {
dirs: [
{ path: myDir, exclude: ['demoApp.js', '.test.js'] },
],
debugToConsole: true,
noduleDefaults: {
middlewares: function(nodule) {
var strRoute = nodule.route.toString();
if (nodule.routeVerb === 'post')
return [doPreForm, doPostForm, sendJsonResponse];
else if (strRoute.indexOf('/json') === 0)
return [doBusinessLogic, sendJsonResponse];
else
return [doBusinessLogic, sendHtmlResponse];
},
// custom properties on top of the nodulejs core properties
templateName: 'default.jade',
templateDir: null,
doNoduleBusinessLogic: function(req, res) { },
},
};
(from demoApp.js)
function doBusinessLogic(req, res, next) {
debug('doBusinessLogic middleware executed for: ' + req.nodule.name);
// app-level business logic can go here
req.nodule.doNoduleBusinessLogic(req, res);
// app-level business logic can also go here
next();
}
(from demoApp.js - goes with Form submit example above)
...
middlewares: function(nodule) {
if (nodule.routeVerb === 'post')
return [doPreForm, doPostForm, sendJsonResponse];
...
function doPreForm(req, res, next) {
req.nodule.doPreFormBusinessLogic(req, res);
makeDbCall({
params: req.nodule.dbParams,
callback: function(err, response) {
req.nodule.responseData = response;
next();
}
});
}
function doPostForm(req, res, next) {
req.nodule.doPostFormBusinessLogic(req, res);
next();
}
// DB simulator, see /json/formSubmit.js
function makeDbCall(call) {
var response = (call.params.param1) ? 'valid data, param1='+call.params.param1 : 'missing param1, please resubmit';
call.callback(null, {dbMsg:response});
}
FAQs
Scalable self-discovering web components
The npm package nodulejs receives a total of 0 weekly downloads. As such, nodulejs popularity was classified as not popular.
We found that nodulejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.